#include "mapinfo.h"
#include "ui_mapinfo.h"
#include <QMessageBox>

mapInfo::mapInfo(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::mapInfo)
{
    ui->setupUi(this);


}

mapInfo::~mapInfo()
{
    delete ui;
}


//提交坐标按钮
void mapInfo::on_pushButton_clicked()
{
    QString SzuoshangX = ui->zuoshangX->toPlainText();
    QString SzuoshangY = ui->zuoshangY->toPlainText();
    QString SyoushangX = ui->youshangX->toPlainText();
    QString SyoushangY = ui->youshangY->toPlainText();
    QString SzuoxiaX = ui->zuoxiaX->toPlainText();
    QString SzuoxiaY = ui->zuoxiaY->toPlainText();
    QString SyouxiaX = ui->youxiaX->toPlainText();
    QString SyouxiaY = ui->youxiaY->toPlainText();

    bool ok; // 用于判断转换是否成功
    zuoshangX = SzuoshangX.toDouble(NULL) * (480 / 120); // 将文本数据转换为浮点数
    zuoshangY = SzuoshangY.toDouble(NULL)* (480 / 120);
    youshangX = SyoushangX.toDouble(NULL) * (480 / 120);
    youshangY = SyoushangY.toDouble(NULL)* (480 / 120);
    zuoxiaX = SzuoxiaX.toDouble(NULL)* (480 / 120);
    zuoxiaY = SzuoxiaY.toDouble(NULL)* (480 / 120);
    youxiaX = SyouxiaX.toDouble(NULL)* (480 / 120);
    youxiaY = SyouxiaY.toDouble(NULL)* (480 / 120);

    if((zuoshangX < 0 || zuoshangX > 480) || (zuoshangY <0 || zuoshangY > 480))
    {
        QMessageBox::information(this, "警告", "左上角坐标不符合要求");
        return;
    }
    if((youshangX < 0 || youshangX > 480) || (youshangY <0 || youshangY > 480))
    {
        QMessageBox::information(this, "警告", "右上角坐标不符合要求");
        return;
    }
    if((zuoxiaX < 0 || zuoxiaX > 480) || (zuoxiaY <0 || zuoxiaY > 480))
    {
        QMessageBox::information(this, "警告", "左下角坐标不符合要求");
        return;
    }
    if((youxiaX < 0 || youxiaX > 480) || (youxiaY <0 || youxiaY > 480))
    {
        QMessageBox::information(this, "警告", "右下角坐标不符合要求");
        return;
    }
    emit mySignal();//发射信号，更新坐标
    QMessageBox::information(this, "成功", "坐标设置成功");
}

